package cn.zzuisa.service.impl;

import cn.zzuisa.service.ConfigService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import cn.zzuisa.entity.Config;
import cn.zzuisa.entity.Reply;
import cn.zzuisa.mapper.ReplyMapper;
import cn.zzuisa.service.ReplyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author frank
 * @since 2019-05-07
 */
@Service
public class ReplyServiceImpl extends ServiceImpl<ReplyMapper, Reply> implements ReplyService {

    @Autowired
    ConfigService configService;

    @Override
    public IPage<Map<String, Object>> pageSelfReplys(IPage<Map<String, Object>> page, Long userId) {
        IPage<Map<String, Object>> result = baseMapper.pageSelfReplys(page, userId);
        result.getRecords().forEach(item -> {
            item.put("levelName",configService.getOne(new QueryWrapper<Config>().eq("config_name",item.get("level"))).getConfigValue());
        });
        return result;
    }

    @Override
    public IPage<Map<String, Object>> pageSelfReplys1(IPage<Map<String, Object>> page, Long invitationId) {
        IPage<Map<String, Object>> result = baseMapper.pageSelfReplys1(page, invitationId);
        result.getRecords().forEach(item -> {
            item.put("levelName",configService.getOne(new QueryWrapper<Config>().eq("config_name",item.get("level"))).getConfigValue());
        });
        return result;
    }
}
